<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精美侧边栏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fa;
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏容器 */
        .sidebar {
            width: 250px;
            background: linear-gradient(180deg, #2c3e50, #1a2530);
            color: white;
            height: 100vh;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 3px 0 15px rgba(0, 0, 0, 0.1);
            position: relative;
            z-index: 100;
        }

        /* 折叠状态下的侧边栏 */
        .sidebar.collapsed {
            width: 70px;
        }

        /* 侧边栏头部 */
        .sidebar-header {
            padding: 20px 15px;
            display: flex;
            align-items: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo {
            width: 32px;
            height: 32px;
            background: linear-gradient(135deg, #3498db, #8e44ad);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 18px;
        }

        .logo-text {
            margin-left: 12px;
            font-size: 20px;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
        }

        .sidebar.collapsed .logo-text {
            display: none;
        }

        /* 折叠按钮 */
        .toggle-btn {
            position: absolute;
            right: -12px;
            top: 20px;
            width: 24px;
            height: 24px;
            background: #3498db;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
            z-index: 101;
        }

        .toggle-btn:hover {
            transform: scale(1.1);
            background: #2980b9;
        }

        .toggle-btn::before {
            content: "◀";
            color: white;
            font-size: 12px;
        }

        .sidebar.collapsed .toggle-btn::before {
            content: "▶";
        }

        /* 菜单列表 */
        .menu-list {
            list-style: none;
            padding: 10px 0;
        }

        /* 菜单项 */
        .menu-item {
            position: relative;
            margin: 5px 0;
        }

        .menu-link {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
            white-space: nowrap;
            overflow: hidden;
        }

        .menu-link:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .menu-icon {
            font-size: 18px;
            width: 24px;
            text-align: center;
            margin-right: 15px;
        }

        .menu-text {
            flex: 1;
            font-size: 15px;
        }

        .sidebar.collapsed .menu-text {
            display: none;
        }

        /* 子菜单指示器 */
        .submenu-indicator {
            margin-left: auto;
            transition: transform 0.3s ease;
        }

        .sidebar.collapsed .submenu-indicator {
            display: none;
        }

        .submenu-indicator.rotated {
            transform: rotate(180deg);
        }

        /* 子菜单 */
        .submenu {
            list-style: none;
            padding-left: 0;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
            background: rgba(0, 0, 0, 0.2);
        }

        .submenu.expanded {
            max-height: 500px;
        }

        .submenu-item .menu-link {
            padding-left: 55px;
            font-size: 14px;
        }

        /* Tooltip样式 */
        .tooltip {
            position: fixed;
            background: white;
            color: #333;
            padding: 12px 16px;
            border-radius: 6px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
            font-size: 14px;
            white-space: nowrap;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transform: translateX(-10px);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            pointer-events: none;
        }

        .tooltip.show {
            opacity: 1;
            visibility: visible;
            transform: translateX(0);
        }

        /* Tooltip箭头 */
        .tooltip::before {
            content: "";
            position: absolute;
            width: 0;
            height: 0;
            border: 6px solid transparent;
            left: -12px;
            top: 50%;
            transform: translateY(-50%);
            border-right-color: white;
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            padding: 30px;
        }

        .content-header {
            margin-bottom: 30px;
        }

        .content-header h1 {
            color: #2c3e50;
            margin-bottom: 10px;
        }

        .content-body {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <div class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <div class="logo">L</div>
            <div class="logo-text">Logo</div>
        </div>
        
        <div class="toggle-btn" id="toggleBtn"></div>
        
        <ul class="menu-list">
            <!-- 一级菜单项 -->
            <li class="menu-item">
                <a href="#" class="menu-link" data-tooltip="仪表盘">
                    <span class="menu-icon">📊</span>
                    <span class="menu-text">仪表盘</span>
                </a>
            </li>
            
            <!-- 带子菜单的一级菜单项 -->
            <li class="menu-item has-submenu">
                <a href="#" class="menu-link" data-tooltip="产品管理">
                    <span class="menu-icon">📦</span>
                    <span class="menu-text">产品管理</span>
                    <span class="submenu-indicator">▼</span>
                </a>
                <ul class="submenu">
                    <li class="submenu-item">
                        <a href="#" class="menu-link" data-tooltip="所有产品">
                            <span class="menu-icon">📋</span>
                            <span class="menu-text">所有产品</span>
                        </a>
                    </li>
                    <li class="submenu-item">
                        <a href="#" class="menu-link" data-tooltip="添加产品">
                            <span class="menu-icon">➕</span>
                            <span class="menu-text">添加产品</span>
                        </a>
                    </li>
                    <li class="submenu-item">
                        <a href="#" class="menu-link" data-tooltip="产品分类">
                            <span class="menu-icon">📂</span>
                            <span class="menu-text">产品分类</span>
                        </a>
                    </li>
                </ul>
            </li>
            
            <li class="menu-item has-submenu">
                <a href="#" class="menu-link" data-tooltip="订单管理">
                    <span class="menu-icon">📝</span>
                    <span class="menu-text">订单管理</span>
                    <span class="submenu-indicator">▼</span>
                </a>
                <ul class="submenu">
                    <li class="submenu-item">
                        <a href="#" class="menu-link" data-tooltip="所有订单">
                            <span class="menu-icon">📋</span>
                            <span class="menu-text">所有订单</span>
                        </a>
                    </li>
                    <li class="submenu-item">
                        <a href="#" class="menu-link" data-tooltip="待处理订单">
                            <span class="menu-icon">⏳</span>
                            <span class="menu-text">待处理订单</span>
                        </a>
                    </li>
                </ul>
            </li>
            
            <li class="menu-item">
                <a href="#" class="menu-link" data-tooltip="客户管理">
                    <span class="menu-icon">👥</span>
                    <span class="menu-text">客户管理</span>
                </a>
            </li>
            
            <li class="menu-item">
                <a href="#" class="menu-link" data-tooltip="数据分析">
                    <span class="menu-icon">📈</span>
                    <span class="menu-text">数据分析</span>
                </a>
            </li>
            
            <li class="menu-item">
                <a href="#" class="menu-link" data-tooltip="系统设置">
                    <span class="menu-icon">⚙️</span>
                    <span class="menu-text">系统设置</span>
                </a>
            </li>
        </ul>
    </div>
    
    <!-- 主内容区域 -->
    <div class="main-content">
        <div class="content-header">
            <h1>欢迎使用管理系统</h1>
            <p>这是一个精美的侧边栏示例页面</p>
        </div>
        <div class="content-body">
            <h2>功能说明</h2>
            <ul>
                <li>点击左侧箭头按钮可以折叠/展开侧边栏</li>
                <li>当侧边栏折叠时，鼠标悬停在菜单项上会显示Tooltip</li>
                <li>带子菜单的项可以点击展开/收起子菜单</li>
                <li>所有动画过渡效果流畅自然</li>
            </ul>
        </div>
    </div>
    
    <!-- Tooltip元素 -->
    <div class="tooltip" id="tooltip"></div>

    <script>
        // 获取DOM元素
        const sidebar = document.getElementById('sidebar');
        const toggleBtn = document.getElementById('toggleBtn');
        const tooltip = document.getElementById('tooltip');
        const menuItems = document.querySelectorAll('.menu-item.has-submenu');
        const menuLinks = document.querySelectorAll('.menu-link');

        // 切换侧边栏折叠状态
        toggleBtn.addEventListener('click', () => {
            sidebar.classList.toggle('collapsed');
        });

        // 处理带子菜单的项的展开/收起
        menuItems.forEach(item => {
            const link = item.querySelector('.menu-link');
            const submenu = item.querySelector('.submenu');
            const indicator = item.querySelector('.submenu-indicator');
            
            link.addEventListener('click', (e) => {
                // 阻止默认链接行为
                e.preventDefault();
                
                // 切换子菜单展开状态
                submenu.classList.toggle('expanded');
                indicator.classList.toggle('rotated');
            });
        });

        // Tooltip显示逻辑
        menuLinks.forEach(link => {
            // 鼠标进入时显示Tooltip
            link.addEventListener('mouseenter', (e) => {
                // 只在侧边栏折叠时显示Tooltip
                if (sidebar.classList.contains('collapsed')) {
                    const tooltipText = link.getAttribute('data-tooltip');
                    tooltip.textContent = tooltipText;
                    
                    // 计算Tooltip位置
                    const rect = link.getBoundingClientRect();
                    tooltip.style.top = rect.top + (rect.height / 2) - (tooltip.offsetHeight / 2) + 'px';
                    tooltip.style.left = (rect.right + 10) + 'px';
                    
                    // 显示Tooltip
                    tooltip.classList.add('show');
                }
            });
            
            // 鼠标离开时隐藏Tooltip
            link.addEventListener('mouseleave', () => {
                tooltip.classList.remove('show');
            });
        });

        // 点击其他地方隐藏Tooltip
        document.addEventListener('click', (e) => {
            if (!tooltip.contains(e.target) && !Array.from(menuLinks).includes(e.target)) {
                tooltip.classList.remove('show');
            }
        });

        // 窗口大小改变时隐藏Tooltip
        window.addEventListener('resize', () => {
            tooltip.classList.remove('show');
        });
    </script>
</body>
</html>
